<template>
  <button @click="isLogin = true">点我登录</button>
<!--  将这个对话框传送到指定位置 其定位也会发生改变 -->
  <teleport to="html">
    <div class="mask" v-show="isLogin">
      <div class="dialog">
        账号:<input type="text"><br>
        密码:<input type="password">
        <br>
        <button>登录</button>
        <br>
        <button @click="isLogin = false">关闭登录</button>
      </div>
    </div>
  </teleport>
</template>

<script>
import {ref} from "vue";
export default {
  name: "my-dialog",
  setup() {
    let isLogin = ref(false);
    return {
      isLogin
    }
  }
}
</script>

<style scoped>
  .mask {
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    left: 0;
    background-color: rgba(0,0,0,0.5);
  }
  .dialog {
    background-color: forestgreen;
    width: 300px;
    height: 300px;
    text-align: center;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
  }
</style>